#ifndef NETWORKWORKER_H
#define NETWORKWORKER_H

#include <QThread>
#include <QNetworkAccessManager>
#include <QNetworkReply>

class NetworkWorker : public QThread
{
    Q_OBJECT

public:
    explicit NetworkWorker(QObject *parent = nullptr);
    void run() override;

    bool m_serverConnected;
    QString m_currentVersion;
    QString m_latestVersion;
    QString m_updateContent;
    QDateTime m_updateTime;
    QString m_deviceName;
    QDateTime m_registrationDate;
    QString m_stregistrationDate;
    QString m_owner;
    QDateTime m_expiryDate;
    QString m_stexpiryDate;
    QString m_endUser;
    QString m_releasedBy;

    void setencryptSequence(QByteArray encryptSequence);


public slots:
    void connectToServer();
    void sendRunningStatus();
    void sendCompressedImage(const QString &imagePath);
    void checkForUpdates();
    void getDeviceInfo();
    void downloadUpdate();
    void handleNetworkError(QNetworkReply *reply);

signals:
    void serverConnectedChanged(bool connected);
    void currentVersionChanged();
    void latestVersionChanged();
    void updateContentChanged();
    void updateTimeChanged();
    void deviceInfoChanged();
    void logMessage(const QString &message);

private:
    QString downloadPath = "master/update_package.zip";
    QString extractPath = ".";
    QString urlPath = "http://192.168.1.167:8000/updater/";
    QNetworkAccessManager *m_networkManager;
    QByteArray encryptSequence_;
    void log(const QString &message);
};

#endif // NETWORKWORKER_H
